<template>
	<view class="beijingse">
		<view class="margin_top1 ffffff mainpadding">
			<view class="xiahuaxian flexleft">
				<view class="xiaohei ershiba fonweight" style="min-width: 200rpx;">开户行</view>
				<input placeholder="请输入开户行名称" type="text" v-model="openbank" />
			</view>
			<view class="xiahuaxian flexleft margin_top">
				<view class="xiaohei ershiba fonweight" style="min-width: 200rpx;">银行卡号</view>
				<input placeholder="请输入银行卡号" type="number" v-model="bankno" />
			</view>
			<view class="xiahuaxian flexleft margin_top">
				<view class="xiaohei ershiba fonweight" style="min-width: 200rpx;">手机号</view>
				<input placeholder="请输入银行预留手机号" type="number" v-model="bankmobile" />
			</view>
			<view class="xiahuaxian flexleft margin_top">
				<view class="xiaohei ershiba fonweight" style="min-width: 200rpx;">持卡人</view>
				<input placeholder="请输入持卡人名称" type="text" v-model="bank_name" />
			</view>
			<view class=" flexleft margin_top">
				<view class="xiaohei ershiba fonweight" style="min-width: 200rpx;">验证码</view>
				<view class="flexbetween">
					<input placeholder="请输入验证码" type="number" v-model="yzm_code" />
					<view class=" xiaohuang smalltext textcenter" style="width: 240rpx;" @click="sendyzm"
						v-show="codetext == 1">获取验证码</view>
					<view class=" xiaohuang smalltext textcenter" style="width: 240rpx;" v-show="codetext == 2">
						{{second}}s后重新获取</view>
					<view class=" xiaohuang smalltext textcenter" style="width: 240rpx;" @click="sendyzm"
						v-show="codetext == 3">重新发送</view>
				</view>
			</view>
		</view>
		<view class="gudingdb mainpadding flexbetween" v-if="isbang">
			<view class="bigbtn" style="width: 45%;background-color: #989898;" @click="jiebang">解除绑定</view>
			<view class="bigbtn" style="width: 45%;" @click="submitFn()">立即绑定</view>
		</view>
		<view class="gudingdb mainpadding flexbetween" v-if="!isbang">
			<view class="bigbtn" @click="submitFn()">立即绑定</view>
		</view>
	</view>
</template>
<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				openbank: "",
				bank_name:"",
				bankno: "",
				captcha: "",
				codetext: 1,
				second: 59,
				bankmobile: '',
				yzm_code: '',
				imgcode: "",
				isbang:false
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			//验证手机号
			isMobile(value) {
				let a = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(value);
				return a;
			},
			//发送验证码
			sendyzm() {
				let _this = this;
				if (_this.bankmobile == '') {
					httpRequest.toast("请输入手机号码!")
					return;
				}
				let device = uni.getSystemInfoSync();
				httpRequest.request('/api/sms/send', 'POST', {
					mobile: this.bankmobile,
					event: 'bankbcer',
				}, false, true, false).then(res => {
					if (res.code == 1) {
						_this.codetext = 2;
						_this.second = 59;
						let timer = setInterval(function() {
							if (_this.second > 1) {
								_this.second--;
							} else {
								clearInterval(timer);
								_this.codetext = 3;
							}
						}, 1000)
						httpRequest.toast('发送成功')
					}else{
						httpRequest.toast(res.msg)
					}
				})
			},
			init() {
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					this.openbank = res.data.openbank
					this.bank_name = res.data.bank_name
					this.bankmobile = res.data.bankmobile
					this.bankno = res.data.bankno
					if(res.data.openbank){
						this.isbang = true
					}
				})
			},
			jiebang(){
				httpRequest.modal('提示', '您去定要解绑当前银行账号吗？', true, (resp) => {
					if (resp) {
						httpRequest.request('/api/user/jbAliInfo', 'GET', {
							type:3
						}).then(res => {
							httpRequest.toast(res.msg)
							if (res.code == 1) {
								setTimeout(() => {
									uni.navigateBack(1)
								}, 1000)
							}
						})
					}
				})
				
			},
			submitFn() {
				if (this.openbank == "") {
					httpRequest.toast("请输入开户行名称")
					return false
				}
				if (this.bankno == "") {
					httpRequest.toast("请输入银行卡号")
					return false
				}
				if (this.bankmobile == "") {
					httpRequest.toast("请输入银行预留手机号")
					return false
				}
				if(this.bank_name==""){
					httpRequest.toast("请输入持卡人名称")
					return false
				}
				if(this.yzm_code==""){
					httpRequest.toast("请输入验证码")
					return false
				}
				httpRequest.request('/api/user/editBankInfo', 'GET', {
					openbank: this.openbank,
					bankmobile: this.bankmobile,
					bankno: this.bankno,
					bank_name: this.bank_name,
					captcha: this.yzm_code,
				}).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					}

				})
			},
		}
	}
</script>

<style>

</style>